package com.yang.interceptor;

import java.util.Map;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.yang.User;
public class LoginInterceptor  extends  AbstractInterceptor {

	private static final long serialVersionUID = 8274536632579253100L;

	@Override
	public String intercept(ActionInvocation ai) throws Exception {
		String actionName=ai.getProxy().getActionName();
		if("index".equals(actionName)||"login".equals(actionName)){
			return ai.invoke();
		}else{
			Map<String, Object> session=ai.getInvocationContext().getSession();
			if(session.containsKey("user")) {
				User user = (User) session.get("user");
				if(user != null) {
					return ai.invoke();
				} else {
					return "index";
				}
			} else {
				return "index";
			}
		}
	}
}
